package com.zhongya666.wan

import android.graphics.Color
import android.os.Bundle
import android.text.SpannableString
import android.text.Spanned
import android.text.TextPaint
import android.text.style.BackgroundColorSpan
import android.text.style.ClickableSpan
import android.text.style.ForegroundColorSpan
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.zhongya666.library.ui.dialog.BasicDialog
import com.zhongya666.wan.databinding.ActivityMainBinding


class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding  = ActivityMainBinding.inflate(layoutInflater)

        setContentView(binding.root)


        binding.timeBtn.letRun()


    }

    fun btn1(view: View){
        val spannableString = SpannableString("我真的很帅我真的很帅我真的很帅我真的很帅我真的很帅我真的很帅我真的很帅\n《我已阅读以上内容》")
//        val backgroundColorSpan = BackgroundColorSpan(Color.GREEN)
        val foregroundColorSpan = ForegroundColorSpan(Color.BLUE)
        spannableString.setSpan(foregroundColorSpan, spannableString.length-10, spannableString.length, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
        val clickableSpan: ClickableSpan = object : ClickableSpan() {

            override fun onClick(widget: View) {
                Toast.makeText(this@MainActivity, "我已阅读以上内容", Toast.LENGTH_SHORT).show()
            }

            override fun updateDrawState(ds: TextPaint) {
                ds.isUnderlineText = false
            }
        }
        spannableString.setSpan(clickableSpan, spannableString.length-10, spannableString.length, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)

        var dialog = BasicDialog(this@MainActivity)
        dialog.setSpanContent(spannableString)
        dialog.show()
    }





}








